<?php

	ob_start();

	session_start();

	include('includes/connect.php');

	$user = $_POST['username'];

	$password = $_POST['password'];

	$query  = "SELECT * FROM users where email_id='".trim($user)."' and active = 'Y'";

	$result = mysql_query($query);

		if(mysql_num_rows($result)!="")
		{ 
			while($row = mysql_fetch_assoc($result))
			{

				if(trim($password)==trim($row['password']))
				{ 
					$_SESSION['user_id']= $row['user_id'];
					$_SESSION['fname']= $row['fname'];
					$_SESSION['lname']= $row['lname'];
					$_SESSION['location'] = $row['location'];
					$_SESSION['gender'] = $row['gender'];
					$_SESSION['birthdate'] = $row['birthdate'];
					$_SESSION['password']= $row['password'];
					$_SESSION['member_type']= $row['member_type'];
					$_SESSION['active']=$row['active'];


					if(isset($_SESSION['url'])) 

					   $url = $_SESSION['url']; // holds url for last page visited.

					   //echo $url;

					else 

					   $url = "myhome.php"; // default page for 

					header("Location: $url"); // perform correct redirect.

					exit;

				} 
				
				else
				{ 

					 header('Location:login.php?er=1');

				 }
			}  
		}

		else

		{ 

			header('Location:login.php?er=2');

		}

		ob_flush();
?>